// 应用常量定义
// 支持需求 3.3, 3.5

/**
 * 产品相关常量
 */
export const PRODUCT_CONSTANTS = {
    // 产品类型
    TYPES: {
        WEBSITE: 'website',
        APP: 'app'
    },

    // 产品类型标签
    TYPE_LABELS: {
        website: '网站',
        app: '应用程序'
    },

    // 字段长度限制
    FIELD_LIMITS: {
        TITLE_MAX_LENGTH: 255,
        DESCRIPTION_MAX_LENGTH: 2000,
        URL_MAX_LENGTH: 500
    },

    // 文件上传限制
    FILE_LIMITS: {
        APP_MAX_SIZE: 100 * 1024 * 1024, // 100MB
        THUMBNAIL_MAX_SIZE: 5 * 1024 * 1024, // 5MB
        ALLOWED_APP_TYPES: ['.exe', '.zip', '.rar', '.7z'],
        ALLOWED_IMAGE_TYPES: ['.jpg', '.jpeg', '.png', '.gif', '.webp']
    }
}

/**
 * API 相关常量
 */
export const API_CONSTANTS = {
    // 端点
    ENDPOINTS: {
        PRODUCTS: '/api/products',
        UPLOAD: '/api/upload'
    },

    // HTTP 方法
    METHODS: {
        GET: 'GET',
        POST: 'POST',
        PUT: 'PUT',
        DELETE: 'DELETE'
    },

    // 状态码
    STATUS_CODES: {
        OK: 200,
        CREATED: 201,
        BAD_REQUEST: 400,
        NOT_FOUND: 404,
        INTERNAL_SERVER_ERROR: 500
    },

    // 错误代码
    ERROR_CODES: {
        VALIDATION_ERROR: 'VALIDATION_ERROR',
        PRODUCT_NOT_FOUND: 'PRODUCT_NOT_FOUND',
        UPLOAD_FAILED: 'UPLOAD_FAILED',
        DATABASE_ERROR: 'DATABASE_ERROR'
    }
}

/**
 * UI 相关常量
 */
export const UI_CONSTANTS = {
    // 分页
    PAGINATION: {
        DEFAULT_PAGE_SIZE: 12,
        PAGE_SIZE_OPTIONS: [6, 12, 24, 48],
        MAX_PAGE_SIZE: 50
    },

    // 搜索
    SEARCH: {
        DEBOUNCE_DELAY: 300, // 搜索防抖延迟（毫秒）
        MIN_SEARCH_LENGTH: 2 // 最小搜索长度
    },

    // 消息提示
    MESSAGES: {
        SUCCESS: {
            PRODUCT_CREATED: '产品创建成功！',
            PRODUCT_UPDATED: '产品更新成功！',
            PRODUCT_DELETED: '产品删除成功！',
            FILE_UPLOADED: '文件上传成功！'
        },
        ERROR: {
            PRODUCT_CREATE_FAILED: '产品创建失败',
            PRODUCT_UPDATE_FAILED: '产品更新失败',
            PRODUCT_DELETE_FAILED: '产品删除失败',
            FILE_UPLOAD_FAILED: '文件上传失败',
            NETWORK_ERROR: '网络连接错误，请稍后重试',
            UNKNOWN_ERROR: '发生未知错误，请稍后重试'
        },
        LOADING: {
            CREATING_PRODUCT: '正在创建产品...',
            UPDATING_PRODUCT: '正在更新产品...',
            DELETING_PRODUCT: '正在删除产品...',
            UPLOADING_FILE: '正在上传文件...',
            LOADING_PRODUCTS: '正在加载产品列表...'
        }
    },

    // 筛选选项
    FILTER_OPTIONS: [
        { value: 'all', label: '全部类型' },
        { value: 'website', label: '网站' },
        { value: 'app', label: '应用程序' }
    ]
}

/**
 * 存储相关常量
 */
export const STORAGE_CONSTANTS = {
    BUCKET_NAME: 'product-files',
    FOLDERS: {
        APPS: 'apps',
        THUMBNAILS: 'thumbnails'
    },
    CACHE_CONTROL: '3600' // 1小时缓存
}

/**
 * 路由常量
 */
export const ROUTES = {
    HOME: '/',
    PRODUCT_DETAIL: '/product/[id]',
    UPLOAD: '/upload',
    API: {
        PRODUCTS: '/api/products',
        PRODUCT_BY_ID: '/api/products/[id]',
        UPLOAD: '/api/upload'
    }
}

/**
 * 默认值常量
 */
export const DEFAULTS = {
    PRODUCT: {
        type: PRODUCT_CONSTANTS.TYPES.WEBSITE,
        title: '',
        description: '',
        url: '',
        thumbnail_url: null
    },

    SEARCH_PARAMS: {
        page: 1,
        limit: UI_CONSTANTS.PAGINATION.DEFAULT_PAGE_SIZE,
        type: 'all',
        search: ''
    }
}